<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Navo Portable Library: navo/algorithm/crypto/symmetric/des.c源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- 制作者 Doxygen 1.7.3 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Navo Portable Library&#160;<span id="projectnumber">Ver 1.0.20120827</span></div>
   <div id="projectbrief">Provides generic platform independent facilities.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="modules.html"><span>模块</span></a></li>
      <li><a href="annotated.html"><span>数据结构</span></a></li>
      <li class="current"><a href="files.html"><span>文件</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="搜索" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>文件列表</span></a></li>
      <li><a href="globals.html"><span>全局定义</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>navo/algorithm/crypto/symmetric/des.c</h1>  </div>
</div>
<div class="contents">
<a href="des_8c.html">浏览该文件的文档。</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */</span>
<a name="l00011"></a>00011 <span class="preprocessor">#ifdef _MSC_VER</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span><span class="preprocessor">#pragma optimize(&quot;t&quot;, on)</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#endif  </span><span class="comment">/* #ifdef _MSC_VER */</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="preprocessor">#include &quot;<a class="code" href="des_8h.html" title="DES.">des.h</a>&quot;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &quot;<a class="code" href="endian_8h.html" title="Definitions for byte order.">../../../port/endian.h</a>&quot;</span>
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00019"></a>00019 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {
<a name="l00020"></a>00020 <span class="preprocessor">#endif </span><span class="comment">/* #ifdef __cplusplus */</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="keyword">static</span> <span class="keyword">const</span> uint32_t SB1[64] = {
<a name="l00023"></a>00023     0x01010400UL, 0x00000000UL, 0x00010000UL, 0x01010404UL,
<a name="l00024"></a>00024     0x01010004UL, 0x00010404UL, 0x00000004UL, 0x00010000UL,
<a name="l00025"></a>00025     0x00000400UL, 0x01010400UL, 0x01010404UL, 0x00000400UL,
<a name="l00026"></a>00026     0x01000404UL, 0x01010004UL, 0x01000000UL, 0x00000004UL,
<a name="l00027"></a>00027     0x00000404UL, 0x01000400UL, 0x01000400UL, 0x00010400UL,
<a name="l00028"></a>00028     0x00010400UL, 0x01010000UL, 0x01010000UL, 0x01000404UL,
<a name="l00029"></a>00029     0x00010004UL, 0x01000004UL, 0x01000004UL, 0x00010004UL,
<a name="l00030"></a>00030     0x00000000UL, 0x00000404UL, 0x00010404UL, 0x01000000UL,
<a name="l00031"></a>00031     0x00010000UL, 0x01010404UL, 0x00000004UL, 0x01010000UL,
<a name="l00032"></a>00032     0x01010400UL, 0x01000000UL, 0x01000000UL, 0x00000400UL,
<a name="l00033"></a>00033     0x01010004UL, 0x00010000UL, 0x00010400UL, 0x01000004UL,
<a name="l00034"></a>00034     0x00000400UL, 0x00000004UL, 0x01000404UL, 0x00010404UL,
<a name="l00035"></a>00035     0x01010404UL, 0x00010004UL, 0x01010000UL, 0x01000404UL,
<a name="l00036"></a>00036     0x01000004UL, 0x00000404UL, 0x00010404UL, 0x01010400UL,
<a name="l00037"></a>00037     0x00000404UL, 0x01000400UL, 0x01000400UL, 0x00000000UL,
<a name="l00038"></a>00038     0x00010004UL, 0x00010400UL, 0x00000000UL, 0x01010004UL
<a name="l00039"></a>00039 };
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="keyword">static</span> <span class="keyword">const</span> uint32_t SB2[64] = {
<a name="l00042"></a>00042     0x80108020UL, 0x80008000UL, 0x00008000UL, 0x00108020UL,
<a name="l00043"></a>00043     0x00100000UL, 0x00000020UL, 0x80100020UL, 0x80008020UL,
<a name="l00044"></a>00044     0x80000020UL, 0x80108020UL, 0x80108000UL, 0x80000000UL,
<a name="l00045"></a>00045     0x80008000UL, 0x00100000UL, 0x00000020UL, 0x80100020UL,
<a name="l00046"></a>00046     0x00108000UL, 0x00100020UL, 0x80008020UL, 0x00000000UL,
<a name="l00047"></a>00047     0x80000000UL, 0x00008000UL, 0x00108020UL, 0x80100000UL,
<a name="l00048"></a>00048     0x00100020UL, 0x80000020UL, 0x00000000UL, 0x00108000UL,
<a name="l00049"></a>00049     0x00008020UL, 0x80108000UL, 0x80100000UL, 0x00008020UL,
<a name="l00050"></a>00050     0x00000000UL, 0x00108020UL, 0x80100020UL, 0x00100000UL,
<a name="l00051"></a>00051     0x80008020UL, 0x80100000UL, 0x80108000UL, 0x00008000UL,
<a name="l00052"></a>00052     0x80100000UL, 0x80008000UL, 0x00000020UL, 0x80108020UL,
<a name="l00053"></a>00053     0x00108020UL, 0x00000020UL, 0x00008000UL, 0x80000000UL,
<a name="l00054"></a>00054     0x00008020UL, 0x80108000UL, 0x00100000UL, 0x80000020UL,
<a name="l00055"></a>00055     0x00100020UL, 0x80008020UL, 0x80000020UL, 0x00100020UL,
<a name="l00056"></a>00056     0x00108000UL, 0x00000000UL, 0x80008000UL, 0x00008020UL,
<a name="l00057"></a>00057     0x80000000UL, 0x80100020UL, 0x80108020UL, 0x00108000UL
<a name="l00058"></a>00058 };
<a name="l00059"></a>00059 
<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keyword">const</span> uint32_t SB3[64] = {
<a name="l00061"></a>00061     0x00000208UL, 0x08020200UL, 0x00000000UL, 0x08020008UL,
<a name="l00062"></a>00062     0x08000200UL, 0x00000000UL, 0x00020208UL, 0x08000200UL,
<a name="l00063"></a>00063     0x00020008UL, 0x08000008UL, 0x08000008UL, 0x00020000UL,
<a name="l00064"></a>00064     0x08020208UL, 0x00020008UL, 0x08020000UL, 0x00000208UL,
<a name="l00065"></a>00065     0x08000000UL, 0x00000008UL, 0x08020200UL, 0x00000200UL,
<a name="l00066"></a>00066     0x00020200UL, 0x08020000UL, 0x08020008UL, 0x00020208UL,
<a name="l00067"></a>00067     0x08000208UL, 0x00020200UL, 0x00020000UL, 0x08000208UL,
<a name="l00068"></a>00068     0x00000008UL, 0x08020208UL, 0x00000200UL, 0x08000000UL,
<a name="l00069"></a>00069     0x08020200UL, 0x08000000UL, 0x00020008UL, 0x00000208UL,
<a name="l00070"></a>00070     0x00020000UL, 0x08020200UL, 0x08000200UL, 0x00000000UL,
<a name="l00071"></a>00071     0x00000200UL, 0x00020008UL, 0x08020208UL, 0x08000200UL,
<a name="l00072"></a>00072     0x08000008UL, 0x00000200UL, 0x00000000UL, 0x08020008UL,
<a name="l00073"></a>00073     0x08000208UL, 0x00020000UL, 0x08000000UL, 0x08020208UL,
<a name="l00074"></a>00074     0x00000008UL, 0x00020208UL, 0x00020200UL, 0x08000008UL,
<a name="l00075"></a>00075     0x08020000UL, 0x08000208UL, 0x00000208UL, 0x08020000UL,
<a name="l00076"></a>00076     0x00020208UL, 0x00000008UL, 0x08020008UL, 0x00020200UL
<a name="l00077"></a>00077 };
<a name="l00078"></a>00078 
<a name="l00079"></a>00079 <span class="keyword">static</span> <span class="keyword">const</span> uint32_t SB4[64] = {
<a name="l00080"></a>00080     0x00802001UL, 0x00002081UL, 0x00002081UL, 0x00000080UL,
<a name="l00081"></a>00081     0x00802080UL, 0x00800081UL, 0x00800001UL, 0x00002001UL,
<a name="l00082"></a>00082     0x00000000UL, 0x00802000UL, 0x00802000UL, 0x00802081UL,
<a name="l00083"></a>00083     0x00000081UL, 0x00000000UL, 0x00800080UL, 0x00800001UL,
<a name="l00084"></a>00084     0x00000001UL, 0x00002000UL, 0x00800000UL, 0x00802001UL,
<a name="l00085"></a>00085     0x00000080UL, 0x00800000UL, 0x00002001UL, 0x00002080UL,
<a name="l00086"></a>00086     0x00800081UL, 0x00000001UL, 0x00002080UL, 0x00800080UL,
<a name="l00087"></a>00087     0x00002000UL, 0x00802080UL, 0x00802081UL, 0x00000081UL,
<a name="l00088"></a>00088     0x00800080UL, 0x00800001UL, 0x00802000UL, 0x00802081UL,
<a name="l00089"></a>00089     0x00000081UL, 0x00000000UL, 0x00000000UL, 0x00802000UL,
<a name="l00090"></a>00090     0x00002080UL, 0x00800080UL, 0x00800081UL, 0x00000001UL,
<a name="l00091"></a>00091     0x00802001UL, 0x00002081UL, 0x00002081UL, 0x00000080UL,
<a name="l00092"></a>00092     0x00802081UL, 0x00000081UL, 0x00000001UL, 0x00002000UL,
<a name="l00093"></a>00093     0x00800001UL, 0x00002001UL, 0x00802080UL, 0x00800081UL,
<a name="l00094"></a>00094     0x00002001UL, 0x00002080UL, 0x00800000UL, 0x00802001UL,
<a name="l00095"></a>00095     0x00000080UL, 0x00800000UL, 0x00002000UL, 0x00802080UL
<a name="l00096"></a>00096 };
<a name="l00097"></a>00097 
<a name="l00098"></a>00098 <span class="keyword">static</span> <span class="keyword">const</span> uint32_t SB5[64] = {
<a name="l00099"></a>00099     0x00000100UL, 0x02080100UL, 0x02080000UL, 0x42000100UL,
<a name="l00100"></a>00100     0x00080000UL, 0x00000100UL, 0x40000000UL, 0x02080000UL,
<a name="l00101"></a>00101     0x40080100UL, 0x00080000UL, 0x02000100UL, 0x40080100UL,
<a name="l00102"></a>00102     0x42000100UL, 0x42080000UL, 0x00080100UL, 0x40000000UL,
<a name="l00103"></a>00103     0x02000000UL, 0x40080000UL, 0x40080000UL, 0x00000000UL,
<a name="l00104"></a>00104     0x40000100UL, 0x42080100UL, 0x42080100UL, 0x02000100UL,
<a name="l00105"></a>00105     0x42080000UL, 0x40000100UL, 0x00000000UL, 0x42000000UL,
<a name="l00106"></a>00106     0x02080100UL, 0x02000000UL, 0x42000000UL, 0x00080100UL,
<a name="l00107"></a>00107     0x00080000UL, 0x42000100UL, 0x00000100UL, 0x02000000UL,
<a name="l00108"></a>00108     0x40000000UL, 0x02080000UL, 0x42000100UL, 0x40080100UL,
<a name="l00109"></a>00109     0x02000100UL, 0x40000000UL, 0x42080000UL, 0x02080100UL,
<a name="l00110"></a>00110     0x40080100UL, 0x00000100UL, 0x02000000UL, 0x42080000UL,
<a name="l00111"></a>00111     0x42080100UL, 0x00080100UL, 0x42000000UL, 0x42080100UL,
<a name="l00112"></a>00112     0x02080000UL, 0x00000000UL, 0x40080000UL, 0x42000000UL,
<a name="l00113"></a>00113     0x00080100UL, 0x02000100UL, 0x40000100UL, 0x00080000UL,
<a name="l00114"></a>00114     0x00000000UL, 0x40080000UL, 0x02080100UL, 0x40000100UL
<a name="l00115"></a>00115 };
<a name="l00116"></a>00116 
<a name="l00117"></a>00117 <span class="keyword">static</span> <span class="keyword">const</span> uint32_t SB6[64] = {
<a name="l00118"></a>00118     0x20000010UL, 0x20400000UL, 0x00004000UL, 0x20404010UL,
<a name="l00119"></a>00119     0x20400000UL, 0x00000010UL, 0x20404010UL, 0x00400000UL,
<a name="l00120"></a>00120     0x20004000UL, 0x00404010UL, 0x00400000UL, 0x20000010UL,
<a name="l00121"></a>00121     0x00400010UL, 0x20004000UL, 0x20000000UL, 0x00004010UL,
<a name="l00122"></a>00122     0x00000000UL, 0x00400010UL, 0x20004010UL, 0x00004000UL,
<a name="l00123"></a>00123     0x00404000UL, 0x20004010UL, 0x00000010UL, 0x20400010UL,
<a name="l00124"></a>00124     0x20400010UL, 0x00000000UL, 0x00404010UL, 0x20404000UL,
<a name="l00125"></a>00125     0x00004010UL, 0x00404000UL, 0x20404000UL, 0x20000000UL,
<a name="l00126"></a>00126     0x20004000UL, 0x00000010UL, 0x20400010UL, 0x00404000UL,
<a name="l00127"></a>00127     0x20404010UL, 0x00400000UL, 0x00004010UL, 0x20000010UL,
<a name="l00128"></a>00128     0x00400000UL, 0x20004000UL, 0x20000000UL, 0x00004010UL,
<a name="l00129"></a>00129     0x20000010UL, 0x20404010UL, 0x00404000UL, 0x20400000UL,
<a name="l00130"></a>00130     0x00404010UL, 0x20404000UL, 0x00000000UL, 0x20400010UL,
<a name="l00131"></a>00131     0x00000010UL, 0x00004000UL, 0x20400000UL, 0x00404010UL,
<a name="l00132"></a>00132     0x00004000UL, 0x00400010UL, 0x20004010UL, 0x00000000UL,
<a name="l00133"></a>00133     0x20404000UL, 0x20000000UL, 0x00400010UL, 0x20004010UL
<a name="l00134"></a>00134 };
<a name="l00135"></a>00135 
<a name="l00136"></a>00136 <span class="keyword">static</span> <span class="keyword">const</span> uint32_t SB7[64] = {
<a name="l00137"></a>00137     0x00200000UL, 0x04200002UL, 0x04000802UL, 0x00000000UL,
<a name="l00138"></a>00138     0x00000800UL, 0x04000802UL, 0x00200802UL, 0x04200800UL,
<a name="l00139"></a>00139     0x04200802UL, 0x00200000UL, 0x00000000UL, 0x04000002UL,
<a name="l00140"></a>00140     0x00000002UL, 0x04000000UL, 0x04200002UL, 0x00000802UL,
<a name="l00141"></a>00141     0x04000800UL, 0x00200802UL, 0x00200002UL, 0x04000800UL,
<a name="l00142"></a>00142     0x04000002UL, 0x04200000UL, 0x04200800UL, 0x00200002UL,
<a name="l00143"></a>00143     0x04200000UL, 0x00000800UL, 0x00000802UL, 0x04200802UL,
<a name="l00144"></a>00144     0x00200800UL, 0x00000002UL, 0x04000000UL, 0x00200800UL,
<a name="l00145"></a>00145     0x04000000UL, 0x00200800UL, 0x00200000UL, 0x04000802UL,
<a name="l00146"></a>00146     0x04000802UL, 0x04200002UL, 0x04200002UL, 0x00000002UL,
<a name="l00147"></a>00147     0x00200002UL, 0x04000000UL, 0x04000800UL, 0x00200000UL,
<a name="l00148"></a>00148     0x04200800UL, 0x00000802UL, 0x00200802UL, 0x04200800UL,
<a name="l00149"></a>00149     0x00000802UL, 0x04000002UL, 0x04200802UL, 0x04200000UL,
<a name="l00150"></a>00150     0x00200800UL, 0x00000000UL, 0x00000002UL, 0x04200802UL,
<a name="l00151"></a>00151     0x00000000UL, 0x00200802UL, 0x04200000UL, 0x00000800UL,
<a name="l00152"></a>00152     0x04000002UL, 0x04000800UL, 0x00000800UL, 0x00200002UL
<a name="l00153"></a>00153 };
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 <span class="keyword">static</span> <span class="keyword">const</span> uint32_t SB8[64] = {
<a name="l00156"></a>00156     0x10001040UL, 0x00001000UL, 0x00040000UL, 0x10041040UL,
<a name="l00157"></a>00157     0x10000000UL, 0x10001040UL, 0x00000040UL, 0x10000000UL,
<a name="l00158"></a>00158     0x00040040UL, 0x10040000UL, 0x10041040UL, 0x00041000UL,
<a name="l00159"></a>00159     0x10041000UL, 0x00041040UL, 0x00001000UL, 0x00000040UL,
<a name="l00160"></a>00160     0x10040000UL, 0x10000040UL, 0x10001000UL, 0x00001040UL,
<a name="l00161"></a>00161     0x00041000UL, 0x00040040UL, 0x10040040UL, 0x10041000UL,
<a name="l00162"></a>00162     0x00001040UL, 0x00000000UL, 0x00000000UL, 0x10040040UL,
<a name="l00163"></a>00163     0x10000040UL, 0x10001000UL, 0x00041040UL, 0x00040000UL,
<a name="l00164"></a>00164     0x00041040UL, 0x00040000UL, 0x10041000UL, 0x00001000UL,
<a name="l00165"></a>00165     0x00000040UL, 0x10040040UL, 0x00001000UL, 0x00041040UL,
<a name="l00166"></a>00166     0x10001000UL, 0x00000040UL, 0x10000040UL, 0x10040000UL,
<a name="l00167"></a>00167     0x10040040UL, 0x10000000UL, 0x00040000UL, 0x10001040UL,
<a name="l00168"></a>00168     0x00000000UL, 0x10041040UL, 0x00040040UL, 0x10000040UL,
<a name="l00169"></a>00169     0x10040000UL, 0x10001000UL, 0x10001040UL, 0x00000000UL,
<a name="l00170"></a>00170     0x10041040UL, 0x00041000UL, 0x00041000UL, 0x00001040UL,
<a name="l00171"></a>00171     0x00001040UL, 0x00040040UL, 0x10000000UL, 0x10041000UL
<a name="l00172"></a>00172 };
<a name="l00173"></a>00173 
<a name="l00174"></a>00174 <span class="comment">/* PC1: left and right halves bit-swap */</span>
<a name="l00175"></a>00175 <span class="keyword">static</span> <span class="keyword">const</span> uint32_t LHS[16] = {
<a name="l00176"></a>00176     0x00000000UL, 0x00000001UL, 0x00000100UL, 0x00000101UL,
<a name="l00177"></a>00177     0x00010000UL, 0x00010001UL, 0x00010100UL, 0x00010101UL,
<a name="l00178"></a>00178     0x01000000UL, 0x01000001UL, 0x01000100UL, 0x01000101UL,
<a name="l00179"></a>00179     0x01010000UL, 0x01010001UL, 0x01010100UL, 0x01010101UL
<a name="l00180"></a>00180 };
<a name="l00181"></a>00181 
<a name="l00182"></a>00182 <span class="keyword">static</span> <span class="keyword">const</span> uint32_t RHS[16] = {
<a name="l00183"></a>00183     0x00000000UL, 0x01000000UL, 0x00010000UL, 0x01010000UL,
<a name="l00184"></a>00184     0x00000100UL, 0x01000100UL, 0x00010100UL, 0x01010100UL,
<a name="l00185"></a>00185     0x00000001UL, 0x01000001UL, 0x00010001UL, 0x01010001UL,
<a name="l00186"></a>00186     0x00000101UL, 0x01000101UL, 0x00010101UL, 0x01010101UL
<a name="l00187"></a>00187 };
<a name="l00188"></a>00188 
<a name="l00189"></a>00189 <span class="comment">/* 初始置换 */</span>
<a name="l00190"></a>00190 <span class="preprocessor">#define IP(x, y) do {                                           \</span>
<a name="l00191"></a>00191 <span class="preprocessor">    t = ((x &gt;&gt;  4) ^ y) &amp; 0x0F0F0F0FUL; y ^= t; x ^= (t &lt;&lt;  4); \</span>
<a name="l00192"></a>00192 <span class="preprocessor">    t = ((x &gt;&gt; 16) ^ y) &amp; 0x0000FFFFUL; y ^= t; x ^= (t &lt;&lt; 16); \</span>
<a name="l00193"></a>00193 <span class="preprocessor">    t = ((y &gt;&gt;  2) ^ x) &amp; 0x33333333UL; x ^= t; y ^= (t &lt;&lt;  2); \</span>
<a name="l00194"></a>00194 <span class="preprocessor">    t = ((y &gt;&gt;  8) ^ x) &amp; 0x00FF00FFUL; x ^= t; y ^= (t &lt;&lt;  8); \</span>
<a name="l00195"></a>00195 <span class="preprocessor">    y = ((y &lt;&lt; 1) | (y &gt;&gt; 31)) &amp; 0xFFFFFFFFUL;                  \</span>
<a name="l00196"></a>00196 <span class="preprocessor">    t = (x ^ y) &amp; 0xAAAAAAAAUL; y ^= t; x ^= t;                 \</span>
<a name="l00197"></a>00197 <span class="preprocessor">    x = ((x &lt;&lt; 1) | (x &gt;&gt; 31)) &amp; 0xFFFFFFFFUL;                  \</span>
<a name="l00198"></a>00198 <span class="preprocessor">} while(0)</span>
<a name="l00199"></a>00199 <span class="preprocessor"></span>
<a name="l00200"></a>00200 <span class="comment">/* 结束置换 */</span>
<a name="l00201"></a>00201 <span class="preprocessor">#define FP(x,y) do {                                            \</span>
<a name="l00202"></a>00202 <span class="preprocessor">    x = ((x &lt;&lt; 31) | (x &gt;&gt; 1)) &amp; 0xFFFFFFFFUL;                  \</span>
<a name="l00203"></a>00203 <span class="preprocessor">    t = (x ^ y) &amp; 0xAAAAAAAAUL; x ^= t; y ^= t;                 \</span>
<a name="l00204"></a>00204 <span class="preprocessor">    y = ((y &lt;&lt; 31) | (y &gt;&gt; 1)) &amp; 0xFFFFFFFFUL;                  \</span>
<a name="l00205"></a>00205 <span class="preprocessor">    t = ((y &gt;&gt;  8) ^ x) &amp; 0x00FF00FFUL; x ^= t; y ^= (t &lt;&lt;  8); \</span>
<a name="l00206"></a>00206 <span class="preprocessor">    t = ((y &gt;&gt;  2) ^ x) &amp; 0x33333333UL; x ^= t; y ^= (t &lt;&lt;  2); \</span>
<a name="l00207"></a>00207 <span class="preprocessor">    t = ((x &gt;&gt; 16) ^ y) &amp; 0x0000FFFFUL; y ^= t; x ^= (t &lt;&lt; 16); \</span>
<a name="l00208"></a>00208 <span class="preprocessor">    t = ((x &gt;&gt;  4) ^ y) &amp; 0x0F0F0F0FUL; y ^= t; x ^= (t &lt;&lt;  4); \</span>
<a name="l00209"></a>00209 <span class="preprocessor">} while(0)</span>
<a name="l00210"></a>00210 <span class="preprocessor"></span>
<a name="l00211"></a>00211 <span class="comment">/* DES循环 */</span>
<a name="l00212"></a>00212 <span class="preprocessor">#define ROUND(x,y) do {                     \</span>
<a name="l00213"></a>00213 <span class="preprocessor">        t = *sk++ ^ x;                      \</span>
<a name="l00214"></a>00214 <span class="preprocessor">        y ^= SB8[(t      ) &amp; 0x3F] ^        \</span>
<a name="l00215"></a>00215 <span class="preprocessor">             SB6[(t &gt;&gt;  8) &amp; 0x3F] ^        \</span>
<a name="l00216"></a>00216 <span class="preprocessor">             SB4[(t &gt;&gt; 16) &amp; 0x3F] ^        \</span>
<a name="l00217"></a>00217 <span class="preprocessor">             SB2[(t &gt;&gt; 24) &amp; 0x3F];         \</span>
<a name="l00218"></a>00218 <span class="preprocessor">        t = *sk++ ^ ((x &lt;&lt; 28) | (x &gt;&gt; 4)); \</span>
<a name="l00219"></a>00219 <span class="preprocessor">        y ^= SB7[(t      ) &amp; 0x3F] ^        \</span>
<a name="l00220"></a>00220 <span class="preprocessor">             SB5[(t &gt;&gt;  8) &amp; 0x3F] ^        \</span>
<a name="l00221"></a>00221 <span class="preprocessor">             SB3[(t &gt;&gt; 16) &amp; 0x3F] ^        \</span>
<a name="l00222"></a>00222 <span class="preprocessor">             SB1[(t &gt;&gt; 24) &amp; 0x3F];         \</span>
<a name="l00223"></a>00223 <span class="preprocessor">    } while(0)</span>
<a name="l00224"></a>00224 <span class="preprocessor"></span>
<a name="l00225"></a>00225 <span class="keyword">static</span> <span class="keywordtype">void</span> __des_key_schedule(uint32_t* sk, <a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>* key)
<a name="l00226"></a>00226 {
<a name="l00227"></a>00227     uint32_t x, y, t;
<a name="l00228"></a>00228     <span class="keywordtype">int</span> i;
<a name="l00229"></a>00229 
<a name="l00230"></a>00230     x = __be32_to_cpu_p(key    );
<a name="l00231"></a>00231     y = __be32_to_cpu_p(key + 4);
<a name="l00232"></a>00232 
<a name="l00233"></a>00233     <span class="comment">/* 置换选择1 */</span>
<a name="l00234"></a>00234     t = ((y &gt;&gt;  4) ^ x) &amp; 0x0F0F0F0FUL; x ^= t; y ^= (t &lt;&lt;  4);
<a name="l00235"></a>00235     t = ((y) ^ x) &amp; 0x10101010UL; x ^= t; y ^= (t);
<a name="l00236"></a>00236 
<a name="l00237"></a>00237     x =   (LHS[(x) &amp; 0xF] &lt;&lt; 3) | (LHS[(x &gt;&gt; 8) &amp; 0xF] &lt;&lt; 2)
<a name="l00238"></a>00238         | (LHS[(x &gt;&gt; 16) &amp; 0xF] &lt;&lt; 1) | (LHS[(x &gt;&gt; 24) &amp; 0xF]     )
<a name="l00239"></a>00239         | (LHS[(x &gt;&gt;  5) &amp; 0xF] &lt;&lt; 7) | (LHS[(x &gt;&gt; 13) &amp; 0xF] &lt;&lt; 6)
<a name="l00240"></a>00240         | (LHS[(x &gt;&gt; 21) &amp; 0xF] &lt;&lt; 5) | (LHS[(x &gt;&gt; 29) &amp; 0xF] &lt;&lt; 4);
<a name="l00241"></a>00241 
<a name="l00242"></a>00242     y =   (RHS[(y &gt;&gt;  1) &amp; 0xF] &lt;&lt; 3) | (RHS[(y &gt;&gt;  9) &amp; 0xF] &lt;&lt; 2)
<a name="l00243"></a>00243         | (RHS[(y &gt;&gt; 17) &amp; 0xF] &lt;&lt; 1) | (RHS[(y &gt;&gt; 25) &amp; 0xF]     )
<a name="l00244"></a>00244         | (RHS[(y &gt;&gt;  4) &amp; 0xF] &lt;&lt; 7) | (RHS[(y &gt;&gt; 12) &amp; 0xF] &lt;&lt; 6)
<a name="l00245"></a>00245         | (RHS[(y &gt;&gt; 20) &amp; 0xF] &lt;&lt; 5) | (RHS[(y &gt;&gt; 28) &amp; 0xF] &lt;&lt; 4);
<a name="l00246"></a>00246 
<a name="l00247"></a>00247     x &amp;= 0x0FFFFFFFUL;
<a name="l00248"></a>00248     y &amp;= 0x0FFFFFFFUL;
<a name="l00249"></a>00249 
<a name="l00250"></a>00250     <span class="comment">/* 计算子密钥 */</span>
<a name="l00251"></a>00251     <span class="keywordflow">for</span>(i = 0; i &lt; 16; i++) {
<a name="l00252"></a>00252         <span class="keywordflow">if</span>(i &lt; 2 || i == 8 || i == 15) {
<a name="l00253"></a>00253             x = ((x &lt;&lt;  1) | (x &gt;&gt; 27)) &amp; 0x0FFFFFFF;
<a name="l00254"></a>00254             y = ((y &lt;&lt;  1) | (y &gt;&gt; 27)) &amp; 0x0FFFFFFF;
<a name="l00255"></a>00255         } <span class="keywordflow">else</span> {
<a name="l00256"></a>00256             x = ((x &lt;&lt;  2) | (x &gt;&gt; 26)) &amp; 0x0FFFFFFF;
<a name="l00257"></a>00257             y = ((y &lt;&lt;  2) | (y &gt;&gt; 26)) &amp; 0x0FFFFFFF;
<a name="l00258"></a>00258         }
<a name="l00259"></a>00259         *sk++ =   ((x &lt;&lt;  4) &amp; 0x24000000UL) | ((x &lt;&lt; 28) &amp; 0x10000000UL)
<a name="l00260"></a>00260                 | ((x &lt;&lt; 14) &amp; 0x08000000UL) | ((x &lt;&lt; 18) &amp; 0x02080000UL)
<a name="l00261"></a>00261                 | ((x &lt;&lt;  6) &amp; 0x01000000UL) | ((x &lt;&lt;  9) &amp; 0x00200000UL)
<a name="l00262"></a>00262                 | ((x &gt;&gt;  1) &amp; 0x00100000UL) | ((x &lt;&lt; 10) &amp; 0x00040000UL)
<a name="l00263"></a>00263                 | ((x &lt;&lt;  2) &amp; 0x00020000UL) | ((x &gt;&gt; 10) &amp; 0x00010000UL)
<a name="l00264"></a>00264                 | ((y &gt;&gt; 13) &amp; 0x00002000UL) | ((y &gt;&gt;  4) &amp; 0x00001000UL)
<a name="l00265"></a>00265                 | ((y &lt;&lt;  6) &amp; 0x00000800UL) | ((y &gt;&gt;  1) &amp; 0x00000400UL)
<a name="l00266"></a>00266                 | ((y &gt;&gt; 14) &amp; 0x00000200UL) | ((y      ) &amp; 0x00000100UL)
<a name="l00267"></a>00267                 | ((y &gt;&gt;  5) &amp; 0x00000020UL) | ((y &gt;&gt; 10) &amp; 0x00000010UL)
<a name="l00268"></a>00268                 | ((y &gt;&gt;  3) &amp; 0x00000008UL) | ((y &gt;&gt; 18) &amp; 0x00000004UL)
<a name="l00269"></a>00269                 | ((y &gt;&gt; 26) &amp; 0x00000002UL) | ((y &gt;&gt; 24) &amp; 0x00000001UL);
<a name="l00270"></a>00270 
<a name="l00271"></a>00271         *sk++ =   ((x &lt;&lt; 15) &amp; 0x20000000UL) | ((x &lt;&lt; 17) &amp; 0x10000000UL)
<a name="l00272"></a>00272                 | ((x &lt;&lt; 10) &amp; 0x08000000UL) | ((x &lt;&lt; 22) &amp; 0x04000000UL)
<a name="l00273"></a>00273                 | ((x &gt;&gt;  2) &amp; 0x02000000UL) | ((x &lt;&lt;  1) &amp; 0x01000000UL)
<a name="l00274"></a>00274                 | ((x &lt;&lt; 16) &amp; 0x00200000UL) | ((x &lt;&lt; 11) &amp; 0x00100000UL)
<a name="l00275"></a>00275                 | ((x &lt;&lt;  3) &amp; 0x00080000UL) | ((x &gt;&gt;  6) &amp; 0x00040000UL)
<a name="l00276"></a>00276                 | ((x &lt;&lt; 15) &amp; 0x00020000UL) | ((x &gt;&gt;  4) &amp; 0x00010000UL)
<a name="l00277"></a>00277                 | ((y &gt;&gt;  2) &amp; 0x00002000UL) | ((y &lt;&lt;  8) &amp; 0x00001000UL)
<a name="l00278"></a>00278                 | ((y &gt;&gt; 14) &amp; 0x00000808UL) | ((y &gt;&gt;  9) &amp; 0x00000400UL)
<a name="l00279"></a>00279                 | ((y      ) &amp; 0x00000200UL) | ((y &lt;&lt;  7) &amp; 0x00000100UL)
<a name="l00280"></a>00280                 | ((y &gt;&gt;  7) &amp; 0x00000020UL) | ((y &gt;&gt;  3) &amp; 0x00000011UL)
<a name="l00281"></a>00281                 | ((y &lt;&lt;  2) &amp; 0x00000004UL) | ((y &gt;&gt; 21) &amp; 0x00000002UL);
<a name="l00282"></a>00282     }
<a name="l00283"></a>00283 
<a name="l00284"></a>00284     <span class="comment">/* 为了安全考虑，擦除内存 */</span>
<a name="l00285"></a>00285     x = 0; y = 0; t = 0;
<a name="l00286"></a>00286 }
<a name="l00287"></a>00287 
<a name="l00288"></a>00288 NV_IMPL <span class="keywordtype">void</span> des_set_key(<a class="code" href="structdes__key.html" title="DES密钥">des_key</a>* key, <span class="keywordtype">void</span>* src_key)
<a name="l00289"></a>00289 {
<a name="l00290"></a>00290     <span class="comment">/* 生成加密密钥 */</span>
<a name="l00291"></a>00291     __des_key_schedule(key-&gt;<a class="code" href="structdes__key.html#aacf524a5b8dc27a80c5bb121a647000b" title="加密钥">esk</a>, (<a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>*)src_key);
<a name="l00292"></a>00292 
<a name="l00293"></a>00293     <span class="comment">/* 生成解密密钥 */</span>
<a name="l00294"></a>00294     <span class="keywordflow">do</span> {
<a name="l00295"></a>00295         <span class="keywordtype">int</span> i;
<a name="l00296"></a>00296         <span class="keywordflow">for</span> (i = 0; i &lt; 32; i += 2) {
<a name="l00297"></a>00297             key-&gt;<a class="code" href="structdes__key.html#a07c8c6325688e2b6ba84395869e4fe2e" title="解密钥">dsk</a>[i    ] = key-&gt;<a class="code" href="structdes__key.html#aacf524a5b8dc27a80c5bb121a647000b" title="加密钥">esk</a>[30 - i];
<a name="l00298"></a>00298             key-&gt;<a class="code" href="structdes__key.html#a07c8c6325688e2b6ba84395869e4fe2e" title="解密钥">dsk</a>[i + 1] = key-&gt;<a class="code" href="structdes__key.html#aacf524a5b8dc27a80c5bb121a647000b" title="加密钥">esk</a>[31 - i];
<a name="l00299"></a>00299         }
<a name="l00300"></a>00300     } <span class="keywordflow">while</span> (0);
<a name="l00301"></a>00301 }
<a name="l00302"></a>00302 
<a name="l00303"></a>00303 NV_IMPL <span class="keywordtype">void</span> __des_crypt(uint32_t* sk, <a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>* dst, <a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>* src)
<a name="l00304"></a>00304 {
<a name="l00305"></a>00305     uint32_t x, y, t;
<a name="l00306"></a>00306 
<a name="l00307"></a>00307     x = __be32_to_cpu_p(src    );
<a name="l00308"></a>00308     y = __be32_to_cpu_p(src + 4);
<a name="l00309"></a>00309 
<a name="l00310"></a>00310     IP(x, y);
<a name="l00311"></a>00311 
<a name="l00312"></a>00312     ROUND(y, x); ROUND(x, y);
<a name="l00313"></a>00313     ROUND(y, x); ROUND(x, y);
<a name="l00314"></a>00314     ROUND(y, x); ROUND(x, y);
<a name="l00315"></a>00315     ROUND(y, x); ROUND(x, y);
<a name="l00316"></a>00316     ROUND(y, x); ROUND(x, y);
<a name="l00317"></a>00317     ROUND(y, x); ROUND(x, y);
<a name="l00318"></a>00318     ROUND(y, x); ROUND(x, y);
<a name="l00319"></a>00319     ROUND(y, x); ROUND(x, y);
<a name="l00320"></a>00320 
<a name="l00321"></a>00321     FP(y, x);
<a name="l00322"></a>00322 
<a name="l00323"></a>00323     *((uint32_t*)(dst    )) = __cpu_to_be32(y);
<a name="l00324"></a>00324     *((uint32_t*)(dst + 4)) = __cpu_to_be32(x);
<a name="l00325"></a>00325 
<a name="l00326"></a>00326     <span class="comment">/* 为了安全考虑，擦除内存 */</span>
<a name="l00327"></a>00327     x = 0; y = 0; t = 0;
<a name="l00328"></a>00328 }
<a name="l00329"></a>00329 
<a name="l00330"></a><a class="code" href="group__DES.html#ga4a767069273a143f63a22fcef5fc7e7e">00330</a> NV_IMPL <span class="keywordtype">void</span> <a class="code" href="group__DES.html#ga4a767069273a143f63a22fcef5fc7e7e" title="设置双重DES密钥">tdes_set_double_key</a>(<a class="code" href="structtdes__key.html" title="三重DES密钥">tdes_key</a>* key, <span class="keywordtype">void</span>* k1, <span class="keywordtype">void</span>* k2)
<a name="l00331"></a>00331 {
<a name="l00332"></a>00332     __des_key_schedule(key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>     , (<a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>*)k1);
<a name="l00333"></a>00333     __des_key_schedule(key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a> + 32, (<a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>*)k2);
<a name="l00334"></a>00334 
<a name="l00335"></a>00335     <span class="keywordflow">do</span> {
<a name="l00336"></a>00336         <span class="keywordtype">int</span> i;
<a name="l00337"></a>00337         <span class="keywordflow">for</span>(i = 0; i &lt; 32; i += 2) {
<a name="l00338"></a>00338             key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[i     ] = key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[30 - i];
<a name="l00339"></a>00339             key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[i +  1] = key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[31 - i];
<a name="l00340"></a>00340             key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[i + 32] = key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[62 - i];
<a name="l00341"></a>00341             key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[i + 33] = key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[63 - i];
<a name="l00342"></a>00342             key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[i + 64] = key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[i     ];
<a name="l00343"></a>00343             key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[i + 65] = key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[i +  1];
<a name="l00344"></a>00344             key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[i + 64] = key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[i     ];
<a name="l00345"></a>00345             key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[i + 65] = key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[i +  1];
<a name="l00346"></a>00346         }
<a name="l00347"></a>00347     } <span class="keywordflow">while</span> (0);
<a name="l00348"></a>00348 }
<a name="l00349"></a>00349 
<a name="l00350"></a><a class="code" href="group__DES.html#gaac393bbf26f0556f80c1d9dd1be6ad51">00350</a> NV_IMPL <span class="keywordtype">void</span> <a class="code" href="group__DES.html#gaac393bbf26f0556f80c1d9dd1be6ad51" title="设置三重DES密钥">tdes_set_triple_key</a>(<a class="code" href="structtdes__key.html" title="三重DES密钥">tdes_key</a>* key, <span class="keywordtype">void</span>* k1, <span class="keywordtype">void</span>* k2, <span class="keywordtype">void</span>* k3)
<a name="l00351"></a>00351 {
<a name="l00352"></a>00352     __des_key_schedule(key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>     , (<a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>*)k1);
<a name="l00353"></a>00353     __des_key_schedule(key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a> + 32, (<a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>*)k2);
<a name="l00354"></a>00354     __des_key_schedule(key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a> + 64, (<a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>*)k3);
<a name="l00355"></a>00355 
<a name="l00356"></a>00356     <span class="keywordflow">do</span> {
<a name="l00357"></a>00357         <span class="keywordtype">int</span> i;
<a name="l00358"></a>00358         <span class="keywordflow">for</span>(i = 0; i &lt; 32; i += 2) {
<a name="l00359"></a>00359             key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[i     ] = key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[94 - i];
<a name="l00360"></a>00360             key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[i +  1] = key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[95 - i];
<a name="l00361"></a>00361             key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[i + 32] = key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[62 - i];
<a name="l00362"></a>00362             key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[i + 33] = key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[63 - i];
<a name="l00363"></a>00363             key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[i + 64] = key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[30 - i];
<a name="l00364"></a>00364             key-&gt;<a class="code" href="structtdes__key.html#aed52ecea39bfbd7a59c3e37a30940b1c" title="解密钥">dsk</a>[i + 65] = key-&gt;<a class="code" href="structtdes__key.html#a0b8f2c599a616bdb64207b2a317b2067" title="加密钥">esk</a>[31 - i];
<a name="l00365"></a>00365         }
<a name="l00366"></a>00366     } <span class="keywordflow">while</span> (0);
<a name="l00367"></a>00367 }
<a name="l00368"></a>00368 
<a name="l00369"></a>00369 NV_IMPL <span class="keywordtype">void</span> __tdes_crypt(uint32_t* sk, <a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>* dst, <a class="code" href="group___xE6_x95_xB4_xE5_x9E_x8B_xE5_xAE_x9A_xE4_xB9_x89.html#gae1affc9ca37cfb624959c866a73f83c2" title="8比特无符号整型">uint8_t</a>* src)
<a name="l00370"></a>00370 {
<a name="l00371"></a>00371     uint32_t x, y, t;
<a name="l00372"></a>00372 
<a name="l00373"></a>00373     x = __be32_to_cpu_p(src    );
<a name="l00374"></a>00374     y = __be32_to_cpu_p(src + 4);
<a name="l00375"></a>00375 
<a name="l00376"></a>00376     IP(x, y);
<a name="l00377"></a>00377 
<a name="l00378"></a>00378     ROUND(y, x); ROUND(x, y);
<a name="l00379"></a>00379     ROUND(y, x); ROUND(x, y);
<a name="l00380"></a>00380     ROUND(y, x); ROUND(x, y);
<a name="l00381"></a>00381     ROUND(y, x); ROUND(x, y);
<a name="l00382"></a>00382     ROUND(y, x); ROUND(x, y);
<a name="l00383"></a>00383     ROUND(y, x); ROUND(x, y);
<a name="l00384"></a>00384     ROUND(y, x); ROUND(x, y);
<a name="l00385"></a>00385     ROUND(y, x); ROUND(x, y);
<a name="l00386"></a>00386 
<a name="l00387"></a>00387     ROUND(x, y); ROUND(y, x);
<a name="l00388"></a>00388     ROUND(x, y); ROUND(y, x);
<a name="l00389"></a>00389     ROUND(x, y); ROUND(y, x);
<a name="l00390"></a>00390     ROUND(x, y); ROUND(y, x);
<a name="l00391"></a>00391     ROUND(x, y); ROUND(y, x);
<a name="l00392"></a>00392     ROUND(x, y); ROUND(y, x);
<a name="l00393"></a>00393     ROUND(x, y); ROUND(y, x);
<a name="l00394"></a>00394     ROUND(x, y); ROUND(y, x);
<a name="l00395"></a>00395 
<a name="l00396"></a>00396     ROUND(y, x); ROUND(x, y);
<a name="l00397"></a>00397     ROUND(y, x); ROUND(x, y);
<a name="l00398"></a>00398     ROUND(y, x); ROUND(x, y);
<a name="l00399"></a>00399     ROUND(y, x); ROUND(x, y);
<a name="l00400"></a>00400     ROUND(y, x); ROUND(x, y);
<a name="l00401"></a>00401     ROUND(y, x); ROUND(x, y);
<a name="l00402"></a>00402     ROUND(y, x); ROUND(x, y);
<a name="l00403"></a>00403     ROUND(y, x); ROUND(x, y);
<a name="l00404"></a>00404 
<a name="l00405"></a>00405     FP(y, x);
<a name="l00406"></a>00406 
<a name="l00407"></a>00407     *((uint32_t*)(dst    )) = __cpu_to_be32(y);
<a name="l00408"></a>00408     *((uint32_t*)(dst + 4)) = __cpu_to_be32(x);
<a name="l00409"></a>00409 
<a name="l00410"></a>00410     <span class="comment">/* 为了安全考虑，擦除内存 */</span>
<a name="l00411"></a>00411     x = 0; y = 0; t = 0;
<a name="l00412"></a>00412 }
<a name="l00413"></a>00413 
<a name="l00414"></a>00414 
<a name="l00415"></a>00415 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00416"></a>00416 <span class="preprocessor"></span>}
<a name="l00417"></a>00417 <span class="preprocessor">#endif </span><span class="comment">/* #ifdef __cplusplus */</span>
<a name="l00418"></a>00418 
</pre></div></div>
</div>
<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>全部</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>数据结构</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>文件</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>函数</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>变量</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>类型定义</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>宏定义</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<hr class="footer"/><address class="footer"><small>Generated at 2015年七月16日 星期四 12:00:37 for Navo Portable Library by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
</body>
</html>
